home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue34 / timetrav / CalConstants.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-03-22  |  3.6 KB  |  101 lines

  1. unit CalConstants;
  2. interface
  3. uses sysutils;
  4. (*
  5.  
  6. These constants and much of the code logic comes from Dr.  John
  7. Stockton's MJD_DATE.PAS.  He has an excellent site at
  8. http://www.merlyn.demon.co.uk jrs@merlyn.demon.co.uk.
  9.  
  10. Any errors in the changes I've made to objectivize it are my fault.
  11. I've modified his constant names by prefixing them with a lower case c,
  12. and some of the types and typed constants have been incorporated into
  13. the TCalenderDef class
  14.  
  15. For more calendar info, see The Calendar FAQ by Claus Tondering - a link
  16. is now maintained at http://www.merlyn.demon.co.uk/misctime.htm - and
  17. Peter Meyer's page.
  18.  
  19. Julian Day Count is the number of days that have elapsed since Greenwich
  20. Mean Noon, Jan. 1, 4713 B.C.; MJD = JD - 2400000.5 . MJD is used because
  21. days start at midnight rather than noon.
  22.  
  23. Here, the Julian Calendar is what it was intended to be; it only agrees
  24. with the Civil Calendar in 45 B.C., then from 8 A.D. to
  25. 1582/1752/whenever.  Years are taken as Jan 1st .. Dec 31st, not always
  26. technically correct.
  27.  
  28.   RULES : G=Gregorian, J=Julian, C=Civil J-G :
  29.   GJ  No Year Zero (except for some Astronomers).
  30.   G.  Every 400 years contains Yrs400 days.
  31.   G.  Every 100 years contains Yrs100 days, unless including xx00/02/29.
  32.   G.  Every   4 years contains Yrs004 days, unless not including xxxx/02/29.
  33.   .J  Every   4 years contains Yrs004 days.
  34.   GJ  Every     year  contains Yrs001 days, unless including xxxx/02/29.
  35.   G.  Greg 1995/10/10 => MJD 50000.
  36.   .J  In Britain, 1752/09/03-13 were omitted;
  37.   .J  Julian 1752/09/02 preceded Gregorian 1752/09/14; therefore
  38.   .J  "Greg 1752/09/12 (MWS -160)" => MJD -38781 => Jul 1752/09/01.
  39.   C   Last Julian (Rome) = 1582/10/04; Last Julian (Britain) = 1752/09/02.
  40.   .J  N.B. Julian was in use from 45 BC, incorrectly until 8 or 12 AD.
  41.  
  42.   Only if Astro is set is the Year Zero included.
  43.   ===================
  44. *)
  45.  
  46. const
  47. cBaseYr = -32000 ;
  48. cYrs001 =           365 ;
  49. cYrs004 = cYrs001* 4 + 1 ;
  50. cYrs100 = cYrs004*25 - 1 ;
  51. cYrs400 = cYrs100* 4 + 1 ;
  52. cGregBias = ( { MJD +50000 => Greg 1995/10/10 }
  53.   cYrs400*(((1995-cBaseYr)        ) div 400) +
  54.   cYrs100*(((1995-cBaseYr) mod 400) div 100) +
  55.   cYrs004*(((1995-cBaseYr) mod 100) div   4) +
  56.   cYrs001*(((1995-cBaseYr) mod   4)        ) +
  57.   31+30+31+30+31+31+30 + 10 ) - 50000 ;
  58. cJulnBias = ( { MJD -38781 => Juln 1752/09/01 }
  59.   cYrs004*(((1752-cBaseYr)        ) div   4) +
  60.   cYrs001*(((1752-cBaseYr) mod   4)        ) +
  61.   31+30+31+30+31+31    +  1 ) + 38781 ;
  62.  
  63. cBaseMo =  3 {Mar} ;
  64. cUltiMo = 14 {Feb} ;
  65. cSpecialMonthsArray : array [cBaseMo..Pred(cUltiMo)] of byte =
  66.   (31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31) ;
  67.  
  68.   {
  69. type
  70. Calendar = (Gregorian, Julian, Civil) ;
  71. ChangeDate = (British, Romish, Other) ;
  72.  
  73. CalN : array [Calendar] of string [9] =
  74.   ('Gregorian', 'JulianCal', 'CivilDate') ;
  75. Bias : array [Gregorian..Julian] of longint = (GregBias, JulnBias) ;
  76. DiMo : array [BaseMo..Pred(UltiMo)] of byte =
  77.   (31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31) ;
  78.  
  79. //ChangeD : ChangeDate = British ;
  80. }
  81. cLastMJDEnglish = -38780 ;  // LastBrit
  82. cLastMJDGreg = -100841 ;    // LastRome
  83. //LastJulianMJD : array [ChangeDate] of longint = (LastBrit, LastRome, 0) ;
  84. //BRO : string [Succ(Ord(High(ChangeDate)))] = 'BRO' ;
  85.  
  86. // Constants added
  87. cJDoffset = 2400000.5;  // MJD + JD = Astronomer's Julian Day Number
  88. cMJD10Oct1995 = 50000;
  89. cMS10Oct1995 = 34982;
  90. cLowerTDateTime = -DateDelta;  {found in systutils.pas}
  91. cUpperTDateTime = DateDelta;   {693594 is value used in Delphi 3.02}
  92.  
  93. {var
  94.  LastJuln : array [ChangeDate] of record Y : integer ; M, D : byte end ;
  95. }
  96.  
  97. implementation
  98.  
  99.  
  100. end.
  101.